package com.huirui.server.controller.admin;

import com.huirui.server.pojo.dto.SeckillDto;
import com.huirui.server.pojo.result.PageResult;
import com.huirui.server.pojo.result.Result;
import com.huirui.server.pojo.vo.SeckillVo;
import com.huirui.server.service.SeckillService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController("adminSeckillController")
@RequestMapping("/admin/seckill")
@Slf4j
@Validated
@Tag(name = "秒杀管理", description = "小程序秒杀管理")
public class SeckillController {

    @Resource
    private SeckillService seckillService;


    @PostMapping("/add/product")
    @Operation(summary = "新增秒杀商品")
    public Result<Void> addNewProduct(@RequestBody @Validated SeckillDto seckillDto) {
        seckillService.addNewProduct(seckillDto);
        return Result.success();
    }

    @GetMapping("/list/product")
    @Operation(summary = "获取秒杀商品列表")
    public Result<PageResult<SeckillVo>> getSeckillProductList(
            @RequestParam(value = "productName", required = false) String productName,
            @RequestParam("page") Long page,
            @RequestParam("pageSize") Long pageSize
    ) {
        PageResult<SeckillVo> res = seckillService.listSeckillProduct(productName, page, pageSize);
        return Result.success(res);
    }


    @DeleteMapping("/delete/product")
    @Operation(summary = "删除秒杀商品")
    public Result<Void> deleteSeckillProduct(@RequestParam("productId") Long productId) {
        seckillService.deleteSeckillProduct(productId);
        return Result.success();
    }

    @PutMapping("/update/product")
    @Operation(summary = "更新秒杀商品")
    public Result<Void> updateProduct(@RequestBody @Validated SeckillDto seckillDto) {
        seckillService.updateProduct(seckillDto);
        return Result.success();
    }
}
